home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 2 / Meeting Pearls Vol. II (1995)(GTI - Schatztruhe)[!].iso / Pearls / dev / Oberon4Amiga / Dialogs / DialogTexts.Mod (.txt) < prev    next >
Oberon Text  |  1994-11-28  |  12KB  |  265 lines

  1. Syntax10.Scn.Fnt
  2. Syntax10i.Scn.Fnt
  3. StampElems
  4. Alloc
  5. 25 Oct 94
  6. Syntax10b.Scn.Fnt
  7. MODULE DialogTexts;
  8.     (** Markus Knasm
  9. ller  8 Jun 94 - 
  10.     IMPORT DialogFrames, Dialogs, Display, Files, GraphicUtils, In, MenuViewers, Oberon, Texts, TextFrames, Viewers;
  11.     CONST 
  12.         W* = 70; H* = 22; white = 0; black = 15; grey1 = 11; minH = 20;
  13.         editMenu = "System.Close System.Copy System.Grow ";
  14.     TYPE
  15.         Item* = POINTER TO ItemDesc;
  16.         ItemDesc* = RECORD(Dialogs.ObjectDesc)
  17.             f: TextFrames.Frame;
  18.         END;
  19.         ChangeMsg = RECORD (Display.FrameMsg);
  20.             x, y: LONGINT;
  21.         END;
  22.     VAR w0: Texts.Writer; 
  23.     PROCEDURE (t: Item) Copy* (VAR dup: Dialogs.Object);
  24.     (** allocates dup and makes a deep copy of o. Before calling this methode dup should be equal NIL *)
  25.         VAR x: Item; t0: Texts.Text;
  26.     BEGIN
  27.         IF dup = NIL THEN NEW (x); dup := x ELSE x := dup(Item) END; 
  28.         t.Copy^ (dup);
  29.         NEW (t0); t0 := TextFrames.Text (""); x.f := TextFrames.NewText (t0, 0)
  30.     END Copy;
  31.     PROCEDURE (t: Item) GetText* (): Texts.Text;
  32.     (** returns the text of the item *)
  33.     BEGIN RETURN t.f.text
  34.     END GetText;
  35.     PROCEDURE GetParText* (n: ARRAY OF CHAR; p: Dialogs.Panel; VAR t: Texts.Text);
  36.     (** returns the generated parameter t, defined by the text items of panel p, which names are contained in n *)
  37.         VAR t0, t1: Texts.Text; s: Texts.Scanner; o: Dialogs.Object;
  38.     BEGIN
  39.         t := TextFrames.Text (""); t0 := TextFrames.Text ("");
  40.         Texts.WriteString (w0, n); Texts.Append (t0, w0.buf);
  41.         Texts.OpenScanner (s, t0, 0); Texts.Scan (s);
  42.         WHILE (s.class # Texts.Char) OR (s.c # 0X) DO
  43.             IF s.class = Texts.Name THEN
  44.                 o := p.NamedObject (s.s);
  45.                 IF (o # NIL) & (o IS Item) THEN
  46.                     t1 := o(Item).GetText ();
  47.                     Texts.Save (t1, 0, t1.len, w0.buf); Texts.WriteString (w0, " ");
  48.                     Texts.Append (t, w0.buf)
  49.                 END
  50.             END;
  51.             Texts.Scan (s)
  52.         END
  53.     END GetParText;
  54.     PROCEDURE DrawFrame (f1, f: Display.Frame; m: BOOLEAN);
  55.         VAR mode: INTEGER;
  56.     BEGIN
  57.         IF m THEN mode := Display.invert ELSE mode := Display.replace END;
  58.         Display.ReplConstC (f1, black, f.X - 1, f.Y, 1, f.H + 1, mode); Display.ReplConstC (f1, white, f.X + f.W, f.Y, 1, f.H + 1, mode);
  59.         Display.ReplConstC (f1, white, f.X, f.Y, f.W - 1, 1, mode); Display.ReplConstC (f1, black, f.X, f.Y + f.H, f.W - 1, 1, mode)
  60.     END DrawFrame;
  61.     PROCEDURE Adjust (f: TextFrames.Frame; id, dY, y, h: INTEGER);
  62.         VAR m: MenuViewers.ModifyMsg;
  63.     BEGIN
  64.         m.id := id; m.dY := dY; m.Y := y; m.H := 0; f.handle (f, m);
  65.         m.id := id; m.dY := dY; m.Y := y; m.H := h; f.handle (f, m);
  66.     END Adjust; 
  67.     PROCEDURE (t: Item) Draw* (x, y: INTEGER; f: Display.Frame);
  68.     (** displays the object at (x, y) in frame f *)
  69.         VAR w, h, w1, h1, ox, oy: INTEGER; 
  70.     BEGIN
  71.         INC (x); t.GetDim (ox, oy, w, h); DEC (w, 2); DEC (h);
  72.         (* checks wether textframe is visible *)
  73.         IF (y + h <= f.Y) OR (y >= f.Y + f.H) OR (x + w <= f.X) OR (x >= f.X + f.W) THEN RETURN END;
  74.         (* corrects x and y such that the lower left coordinats of the textframes are visible *)
  75.         IF (x < f.X) & (x + w > f.X) THEN w := w - (f.X - x); x := f.X END;    
  76.         IF (y < f.Y) & (y + h > f.Y) THEN  h := h- (f.Y - y); y := f.Y END;
  77.         (* corrects wide and height such that the full textframe can be displayed *)
  78.         w1 := f.W - (x - f.X); h1 := f.H - (y - f.Y);
  79.         IF w1 < t.f.left THEN RETURN END;
  80.         IF w > w1 THEN w := w1 END; IF h > h1 THEN h := h1 END;
  81.         IF w < 0 THEN w := 0 END; IF h < 0 THEN h := 0 END;
  82.         t.f.X := x; t.f.Y := y; t.f.W := w; t.f.H := h; 
  83.         Oberon.RemoveMarks (f.X, f.Y, f.W, f.H); DrawFrame (f, t.f, t.selected);
  84.         t.f.barW := 0; t.f.left := 3; t.f.right := 3; t.f.bot := 3; t.f.top := 3;  
  85.         Adjust (t.f, MenuViewers.extend, 0, t.f.Y + 1, t.f.H - 1);
  86.     END Draw;
  87.     PROCEDURE (t: Item) Print* (x, y: INTEGER);
  88.     (** prints the object at printer coordinates (x, y) *)
  89.         VAR ox, oy, ow, oh: INTEGER;
  90.     BEGIN t.GetPDim (ox, oy, ow, oh); GraphicUtils.PrintBox (x, y, ow, oh)
  91.     END Print;
  92.     PROCEDURE (t: Item) Handle* (f: Display.Frame; VAR msg: Display.FrameMsg);
  93.     (** handles messages which were sent to frame f *)
  94.         VAR x, y, w, h, xh, yh: INTEGER; v: Viewers.Viewer; msg1: Oberon.CopyMsg; 
  95.             f1: Display.Frame; cond: BOOLEAN; msg2: ChangeMsg; t1: Texts.Text;
  96.     BEGIN    
  97.         t.Handle^ (f, msg); t.GetDim (x, y, w, h);
  98.         (* checks textframe is visible *)
  99.         WITH f: DialogFrames.Frame DO
  100.             yh := f.Y + f.H + y; xh := f.X + x; 
  101.             IF (yh + h <= f.Y) OR (yh >= f.Y + f.H) OR (xh + w <= f.X) OR (xh >= f.X + f.W) OR (h < minH) THEN RETURN END;
  102.             IF (f.X <= t.f.X) & (f.X + f.W >= t.f.X) & (f.Y <= t.f.Y) & (f.Y + f.H >= t.f.Y) THEN
  103.                 IF msg IS TextFrames.UpdateMsg THEN 
  104.                     IF msg(TextFrames.UpdateMsg).text = t.f.text THEN 
  105.                         t.f.handle (t.f, msg); msg2.x := f.X; msg2.y := f.Y; Viewers.Broadcast (msg2);
  106.                         IF (f.X > t.f.X) OR (f.X + f.W < t.f.X) OR (f.Y > t.f.Y) OR (f.Y + f.H < t.f.Y) THEN
  107.                             t.Draw (f.X + x, f.Y + f.H + y, f); 
  108.                         END;
  109.                         IF t.cmd[0] # 0X THEN 
  110.                             GetParText (t.par, t.panel, t1);
  111.                             t.CallCmd (f, Viewers.This (xh, yh), t1) 
  112.                         END
  113.                     END 
  114.                 ELSE 
  115.                     t.f.handle (t.f, msg); 
  116.                 END;
  117.             ELSE 
  118.                 cond := FALSE; 
  119.                 WITH msg: Oberon.InputMsg DO 
  120.                     IF (msg.id = Oberon.track) & 
  121.                         (msg.X >= xh) & (msg.X <= xh + w) & (msg.Y >= yh) & (msg.Y <= yh+ h) & (msg. keys # {}) THEN cond := TRUE; 
  122.                     END;
  123.                     IF msg.id = Oberon.defocus THEN cond := TRUE END
  124.                 | msg: ChangeMsg DO
  125.                         t.Draw (f.X + x, f.Y + f.H + y, f);
  126.                 ELSE  
  127.                 END;
  128.                 IF cond THEN 
  129.                     TextFrames.RemoveCaret (t.f); t.Draw (f.X + x, f.Y + f.H + y, f); t.f.handle (t.f, msg); 
  130.                 END;
  131.             END
  132.         ELSE
  133.         END; 
  134.     END Handle;
  135.     PROCEDURE (t: Item) Init*;
  136.     (** initialies the object, should be called after allocating the object with NEW *)
  137.         VAR h: Texts.Text;
  138.     BEGIN t.Init^; h := TextFrames.Text (""); t.f := TextFrames.NewText (h, 0);
  139.     END Init;
  140.     PROCEDURE Insert*;
  141.     (** Insert ([name] [x y w h] | ^ ) inserts a text - item in the panel containing the caret position *)
  142.         VAR x, y, x1, y1, w, h: INTEGER; t: Item; p: Dialogs.Panel; name: ARRAY 64 OF CHAR;
  143.     BEGIN
  144.         NEW (t);
  145.         DialogFrames.GetCaretPosition (p, x, y);
  146.         IF (p # NIL) THEN     
  147.             t.Init; In.Open; In.Name (name);
  148.             IF ~In.Done THEN COPY ("", name); In.Open END;
  149.             t.SetName (name); 
  150.             In.Int (x1); In.Int (y1); In.Int (w); In.Int (h);
  151.             IF ~In.Done THEN x1 := x; y1 := y; w := W; h := H 
  152.             ELSE
  153.                 IF w < 0 THEN w := W END;
  154.                 IF h < 0 THEN h := H END
  155.             END;
  156.             t.SetDim (x1, y1, w, h, FALSE); p.Insert (t, FALSE) 
  157.         ELSE
  158.             Dialogs.res := Dialogs.noPanelSelected
  159.         END;
  160.         IF Dialogs.res # 0 THEN Dialogs.Error ("DialogTexts") END;
  161.     END Insert;
  162.     PROCEDURE WriteToObjectInt (o: Dialogs.Object; VAR p: Dialogs.Panel; x: INTEGER);
  163.         VAR t: Texts.Text;
  164.     BEGIN
  165.         WITH o: Item DO
  166.             t := o.GetText (); Texts.WriteInt (w0, x, 1); Texts.Append (t, w0.buf);
  167.         END
  168.     END WriteToObjectInt;
  169.     PROCEDURE WriteToObjectStr (o: Dialogs.Object; VAR p: Dialogs.Panel; n: ARRAY OF CHAR);
  170.         VAR t: Texts.Text;
  171.     BEGIN
  172.         WITH o: Item DO
  173.             t := o.GetText (); Texts.WriteString (w0, n); Texts.Append (t, w0.buf);
  174.         END
  175.     END WriteToObjectStr;
  176.     PROCEDURE Edit (o: Dialogs.Object);
  177.         VAR
  178.             x, y, nx, ny, nw, nh: INTEGER; nn, nc, np: ARRAY 64 OF CHAR;
  179.             ox, oy, ow, oh, on, oc, op: Dialogs.Object; deInit: Dialogs.Panel;
  180.             msg: DialogFrames.GetFrameMsg; file: Files.File; r: Files.Rider;
  181.             m: TextFrames.Frame; v: Viewers.Viewer; df: DialogFrames.Frame;
  182.     BEGIN
  183.         Oberon.AllocateSystemViewer (Oberon.Mouse.X, x, y);
  184.         msg.p := Dialogs.editPanel; msg.f := NIL; Viewers.Broadcast (msg);
  185.         IF msg.f = NIL THEN
  186.             NEW (df); deInit := Dialogs.deInit.Copy (); 
  187.             df.Open (DialogFrames.Handle, deInit); 
  188.             Oberon.AllocateSystemViewer (Oberon.Mouse.X, x, y);
  189.             m := TextFrames.NewMenu ("DEInit.Dlg", editMenu);
  190.             v := MenuViewers.New (m, df, TextFrames.menuH, x, y);
  191.         ELSE
  192.             deInit := Dialogs.deInit.Copy (); msg.f.panel := deInit; deInit.Restore;
  193.         END;
  194.         ox := deInit.NamedObject ("x");  oy := deInit.NamedObject ("y");
  195.         ow := deInit.NamedObject ("w"); oh := deInit.NamedObject ("h");
  196.         on := deInit.NamedObject ("name"); oc := deInit.NamedObject ("cmd");
  197.         op := deInit.NamedObject ("par");
  198.         o.GetDim (nx, ny, nw, nh); COPY (o.name, nn); COPY (o.cmd, nc); COPY (o.par, np);
  199.         WriteToObjectInt (ox,  deInit, nx); WriteToObjectInt (oy, deInit, ny);
  200.         WriteToObjectInt (ow, deInit, nw); WriteToObjectInt (oh, deInit, nh);
  201.         WriteToObjectStr (on, deInit, nn); WriteToObjectStr (oc, deInit, nc);
  202.         WriteToObjectStr (op, deInit, np);
  203.         Dialogs.editPanel := deInit; Dialogs.editObject := o;
  204.     END Edit;
  205.     PROCEDURE Update (o: Dialogs.Object; deInit: Dialogs.Panel);
  206.         VAR 
  207.             o1: Dialogs.Object;
  208.             ax, ay, aw, ah, nx, ny, nw, nh, res, res1, res2, res3, res4: INTEGER;
  209.             nn: ARRAY 32 OF CHAR; nc, np: ARRAY 64 OF CHAR;  
  210.             par: Oberon.ParList; t: Texts.Text; 
  211.         PROCEDURE ReadInt (o: Dialogs.Object; VAR x, res: INTEGER);
  212.             VAR s: Texts.Scanner;
  213.         BEGIN
  214.             WITH o: Item DO 
  215.                 t := o.GetText (); Texts.OpenScanner (s, t, 0); Texts.Scan (s);
  216.                 IF (s.class = Texts.Int) THEN x := SHORT (s.i); res := Dialogs.ok ELSE res := Dialogs.wrongInput END
  217.             ELSE
  218.             END;
  219.         END ReadInt;
  220.         PROCEDURE InitPar (VAR par: Oberon.ParList);
  221.         BEGIN
  222.             NEW (par); NEW (par.text);
  223.             par.text := TextFrames.Text (""); par.vwr := Oberon.FocusViewer; par.frame := Oberon.Par.frame
  224.         END InitPar;
  225.     BEGIN
  226.         o1 := deInit.NamedObject ("name");
  227.         WITH o1: Item DO
  228.             InitPar (par);
  229.             t := o1.GetText (); Texts.Save (t, 0, t.len, w0.buf); Texts.Append (par.text, w0.buf);
  230.             Texts.WriteString (w0, " "); Texts.Append (par.text, w0.buf); DialogFrames.SetCaretAtObject (o);
  231.             IF t.len > 0 THEN Oberon.Call ("Dialog.SetName", par, FALSE, res) END
  232.         END;
  233.         o1 := deInit.NamedObject ("cmd");
  234.         WITH o1: Item DO    
  235.             InitPar (par);
  236.             t := o1.GetText (); Texts.Save (t, 0, t.len, w0.buf); Texts.Append (par.text, w0.buf);
  237.             Texts.WriteString (w0, " "); Texts.Append (par.text, w0.buf); DialogFrames.SetCaretAtObject (o);
  238.             IF t.len > 0 THEN Oberon.Call ("Dialog.SetCmd", par, FALSE, res) END
  239.         END;
  240.         o1 := deInit.NamedObject ("par");
  241.         WITH o1: Item DO    
  242.             InitPar (par);
  243.             t := o1.GetText (); Texts.Save (t, 0, t.len, w0.buf); Texts.Append (par.text, w0.buf);
  244.             Texts.WriteString (w0, " "); Texts.Append (par.text, w0.buf); DialogFrames.SetCaretAtObject (o);
  245.             IF t.len > 0 THEN Oberon.Call ("Dialog.SetPar", par, FALSE, res) END
  246.         END;
  247.         o1 := deInit.NamedObject ("x"); ReadInt (o1, nx, res1);
  248.         o1 := deInit.NamedObject ("y"); ReadInt (o1, ny, res2);
  249.         o1 := deInit.NamedObject ("w"); ReadInt (o1, nw, res3);
  250.         o1 := deInit.NamedObject ("h"); ReadInt (o1, nh, res4);
  251.         IF (res1 # Dialogs.ok) OR (res2 # Dialogs.ok) OR (res3 # Dialogs.ok) OR (res4 # Dialogs.ok) THEN 
  252.             Dialogs.res := Dialogs.wrongInput; Dialogs.Error ("Dialog"); 
  253.         ELSE
  254.             o.GetDim (ax, ay, aw, ah);
  255.             IF (ax # nx) OR (ay # ny) OR (aw # nw) OR (ah # nh) THEN
  256.                 InitPar (par); 
  257.                 Texts.WriteInt (w0, nx, 5); Texts.WriteInt (w0, ny, 5); Texts.WriteInt (w0, nw, 5); Texts.WriteInt (w0, nh, 5);
  258.                 Texts.WriteString (w0, " "); Texts.Append (par.text, w0.buf); DialogFrames.SetCaretAtObject (o);
  259.                 Oberon.Call ("Dialog.SetDim", par, FALSE, res)
  260.             END;
  261.         END;
  262.     END Update;
  263. BEGIN Texts.OpenWriter (w0); Dialogs.Edit := Edit; Dialogs.Update := Update
  264. END DialogTexts.
  265.